package com.hcxdi.api.convert;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

/**
 * 文件上传转换器
 * @author 成都青桔科技有限公司
 * @version 1.0
 * @changelog 16-11-9 初始化
 * @use @Part("fileName") File file
 */
public class FileRequestBodyConverterFactory extends Converter.Factory {
    @Override
    public Converter<File, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
        return new FileRequestBodyConverter();
    }
}
 class FileRequestBodyConverter implements Converter<File, RequestBody> {
    @Override
    public RequestBody convert(File file) throws IOException {
        return RequestBody.create(MediaType.parse("application/otcet-stream"), file);
    }
}
